package emergency.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.whu.zj.MyApplication;
import com.whu.zj.R;

import java.util.ArrayList;
import java.util.List;

import emergency.dto.AlertRecordDto;

/**
 * 预警内容查看
 * Created by Administrator on 2016/3/15.
 */
public class EmergencyRecordAdapter extends BaseAdapter{

    List<AlertRecordDto> alerts = new ArrayList<AlertRecordDto>();

    public void setAlerts(List<AlertRecordDto> alerts) {
        this.alerts = alerts;
    }

    @Override
    public int getCount() {
        return alerts.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null)
        {
            viewHolder = new ViewHolder();
            convertView = View.inflate(MyApplication.share(), R.layout.item_alertemergencyrecord,null);
            viewHolder.tv_type = (TextView) convertView.findViewById(R.id.id_tv_type);
            viewHolder.tv_plant = (TextView) convertView.findViewById(R.id.id_tv_plant);
            viewHolder.tv_station = (TextView) convertView.findViewById(R.id.id_tv_station);
            viewHolder.tv_value = (TextView) convertView.findViewById(R.id.id_tv_value);
            viewHolder.tv_diposePerson = (TextView) convertView.findViewById(R.id.id_tv_disposePerson);
            viewHolder.tv_maxvalue = (TextView) convertView.findViewById(R.id.id_tv_maxvalue);
            viewHolder.tv_minvalue = (TextView) convertView.findViewById(R.id.id_tv_minvalue);
            viewHolder.tv_time = (TextView) convertView.findViewById(R.id.id_tv_time);
            viewHolder.v_dipose =  convertView.findViewById(R.id.id_v_dipose);
            viewHolder.img_alerttag = (ImageView) convertView.findViewById(R.id.id_img_alerttag);
            convertView.setTag(viewHolder);
        }
        else
        {
            viewHolder = (ViewHolder) convertView.getTag();
        }


        AlertRecordDto alert = alerts.get(position);
        String type = alert.getAlertType();
//        String content = alert.getAlertContent();
//        viewHolder.tv_type.setText(type==null?"无":type);
//        viewHolder.tv_content.setText(content==null?"无":content);

        viewHolder.tv_type.setText(type);
        viewHolder.tv_plant.setText(alert.getAlertWaterPlant());
        viewHolder.tv_station.setText(alert.getAlertPlace());
        viewHolder.tv_time.setText(alert.getId().getTime());
        viewHolder.tv_value.setText(alert.getValue());
        viewHolder.tv_minvalue.setText(alert.getLowervalue());
        viewHolder.tv_maxvalue.setText(alert.getUppervalue());
        viewHolder.tv_diposePerson.setText(alert.getDisposealertname());

        if (alert.getFlag().equals("0"))
        {
            viewHolder.v_dipose.setVisibility(View.GONE);
            viewHolder.img_alerttag.setVisibility(View.VISIBLE);
        }
        else
        {
            viewHolder.v_dipose.setVisibility(View.VISIBLE);
            viewHolder.img_alerttag.setVisibility(View.GONE);
        }
        return convertView;
    }

    private static class ViewHolder
    {
        public TextView tv_time;
        public TextView tv_plant;
        public TextView tv_station;
        public TextView tv_type;
        public TextView tv_value;
        public TextView tv_maxvalue;
        public TextView tv_minvalue;
        public TextView tv_diposePerson;
        View v_dipose;
        ImageView img_alerttag;
    }
}
